from .database import Base, engine, SessionLocal
from ..models.transaction import Transaction
import uuid

def init_db():
    Base.metadata.drop_all(bind=engine)
    Base.metadata.create_all(bind=engine)
    
    # 创建测试数据
    db = SessionLocal()
    try:
        # 添加一些测试交易记录
        test_transaction = Transaction(
            id=str(uuid.uuid4()),
            trans_code="CEP",
            trans_sn="C0002025071110334802603840",
            rrn="519210550877",
            orderid="TEST202507119184",
            pan="2168890010126843",
            trans_amt="00000000150",
            trans_date="20250711",
            trans_time="103348",
            merno="999999999999997",
            terminal="99999996",
            resp_code="0000",
            bank_date="20250711",
            pay_order="TEST202507119184"
        )
        db.add(test_transaction)
        db.commit()
    except Exception as e:
        print(f"Error creating test data: {e}")
        db.rollback()
    finally:
        db.close()

if __name__ == "__main__":
    init_db()
    print("数据库初始化完成！") 